package com.qiyeji.real_estate.controller;

import com.qiyeji.real_estate.entity.TemporaryWorkKey;
import com.qiyeji.real_estate.entity.workKey;
import com.qiyeji.real_estate.service.WorkService;
import com.qiyeji.real_estate.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/Work")
@RestController
@ResponseBody
public class WorkController {
    @Autowired
    WorkService workService;

    @PostMapping("/getAllWorkKey")
    public Result getAllWorkKey() {
        List<workKey> workKey = workService.getAllWorkKey();
        if(workKey==null) {
            return Result.error();
        }
        else {
            return Result.success(workKey);
        }
    }

    @PostMapping("/insert")
    public Result insert(@RequestBody workKey workKey){
        int res=workService.insert(workKey);
        if(res==0) {
            return Result.error();
        }
        else {
            return Result.success(res);
        }
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody workKey workKey){
        int res=workService.delete(workKey);
        if(res==0){
            return Result.error();
        }else{
            return Result.success(res);
        }
    }

    @PostMapping("/fuzzyQuery")
    public Result fuzzyQuery(@RequestBody Map<String,String> params){
        String key = params.get("key");
        List<workKey> workKey = workService.fuzzyQuery(key);
        if(workKey==null) {
            return Result.error();
        }
        else {
            return Result.success(workKey);
        }
    }

    @PostMapping("/fuzzyQuery1")
    public Result fuzzyQuery1(@RequestBody Map<String, String> params) {
        String pCode = params.get("pCode");
        List<TemporaryWorkKey> workKeys = workService.fuzzyQuery1(pCode);
        if (workKeys == null)
            return Result.error();
        else
            return Result.success(workKeys);
    }
}
